import { GuildCopyEntrancePanelBase } from "./GuildCopyEntrancePanelBase";
import { ObjCreate } from "../../../common/ObjCreate";
import { DataProvider } from "../../../../../../fl/data/DataProvider";
import { CopyConfig } from "../../../../resource/CopyConfig";
import { GTextFormat } from "../../../../../common/GTextFormat";
import { FontUtil } from "../../../../../common/font/FontUtil";
import { GlobalStyle } from "../../../../../common/global/GlobalStyle";
import { GSprite } from "../../../../../../com/mui/controls/GSprite";
import { GScrollPane } from "../../../../../../com/mui/controls/GScrollPane";
import { ScrollPolicy } from "../../../../../../fl/controls/ScrollPolicy";
import { Language } from "../../../../../../extend/language/Language";
import { Dispatcher } from "../../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../../events/DataEvent";
import { EventName } from "../../../../mvc/EventName";
import { Cache } from "../../../../cache/Cache";
import { Global } from "../../../../../../com/gengine/global/Global";
import { ECopyType } from "../../../../../../Message/Public/ECopyType";
import { HighlightManager } from "../../../../manager/HighlightManager";
import { GLabel } from "../../../../../../com/mui/controls/GLabel";
import { GComboBox } from "../../../../../../com/mui/controls/GComboBox";
import { GTextFiled } from "../../../../../../com/mui/controls/GTextFiled";
import { GButton } from "../../../../../../com/mui/controls/GButton";
type int = number;
//class GuildDefenseEntrancePanel
    
    export  class GuildDefenseEntrancePanel extends GuildCopyEntrancePanelBase
    {
        constructor()
        {
            super();
            this.createChildren();
            return;
        }

        protected createChildren(): void
        {
            ObjCreate.createLoadedBitmap("text_moshoulaixi.png", 23, 66, this);
            this._numLabel = ObjCreate.createLabel("", 122, 68, 50, 20, flash.text.TextFormatAlign.LEFT, this, true, 16776960);
            this._diffData = new DataProvider(CopyConfig.instance.getGuildDefenseDiffArr());
            this._difficulCb = ObjCreate.createGComboBox(225, 62, 95, 25, this._diffData, this);
            var loc1=new GTextFormat(FontUtil.songtiName, 12, GlobalStyle.color1Uint, null, null, null, null, null, null, null, null, null, 3);
            var loc2=new GSprite();
            this._descText0 = ObjCreate.createGTextField("", 0, 0, 290, 230, loc2, loc1);
            this._descText0.wordWrap = true;
            this._descText0.multiline = true;
            this._descText0.mouseWheelEnabled = false;
            this._descText0.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._descText0.htmlText = CopyConfig.instance.getGuildCopyDesc(4);
            this._descText1 = ObjCreate.createGTextField("", 0, this._descText0.y + this._descText0.height + 5, 290, 230, loc2, loc1);
            this._descText1.wordWrap = true;
            this._descText1.multiline = true;
            this._descText1.mouseWheelEnabled = false;
            this._descText1.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._descText1.htmlText = CopyConfig.instance.getGuildCopyDesc(5);
            this._descText2 = ObjCreate.createGTextField("", 0, this._descText1.y + this._descText1.height + 5, 290, 230, loc2, loc1);
            this._descText2.wordWrap = true;
            this._descText2.multiline = true;
            this._descText2.mouseWheelEnabled = false;
            this._descText2.autoSize = flash.text.TextFieldAutoSize.LEFT;
            this._descText2.htmlText = CopyConfig.instance.getGuildCopyDesc(6);
            var loc3=new GScrollPane();
            loc3.x = 28;
            loc3.y = 100;
            loc3.width = 300;
            loc3.height = 245;
            loc3.styleName = "GScrollPane";
            loc3.verticalScrollPolicy = ScrollPolicy.AUTO;
            loc3.horizontalScrollPolicy = ScrollPolicy.OFF;
            loc3.source = loc2;
            loc3.scrollDrag = false;
            loc3.setScrollBarSize(19);
            addChild(loc3);
            loc3.update();
            this._optBtn = ObjCreate.createGButton(Language.getString(60407), 135, 355, 72, 26, this);
            this._optBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onOptButtonClick);
            return;
        }

        /* internal  */onOptButtonClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=this._optBtn.label;
            switch (loc1) 
            {
                case Language.getString(60407):
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.CopyOpenGuildDefense, this._difficulCb.selectedItem["value"]));
                    break;
                }
                case Language.getString(60408):
                {
                    Dispatcher.dispatchEvent(new DataEvent(EventName.CopyEnterGuildDefense));
                    break;
                }
            }
            return;
        }

        public /* override */ updateStatus(): void
        {
            this.updateDiffArr();
            var loc1=Cache.instance.copy.guildDefenseInfo;
            this._numLabel.htmlText = "（" + loc1.weekCount + "/2）";
            var loc2=true;
            var loc3=true;
            var loc4=false;
            if (loc1) 
            {
                if (loc1.weekCount > 2 && !Global.isDebugModle) 
                {
                    this._optBtn.label = Language.getString(60407);
                    loc3 = false;
                }
                else if (loc1.hasOpen) 
                {
                    this._optBtn.label = Language.getString(60408);
                    this.setDiffCbSelected(loc1.difficult);
                    loc2 = false;
                    loc4 = true;
                    if (Cache.instance.copy.isInCopyType(ECopyType._ECopyGuildDefense)) 
                    {
                        loc3 = false;
                        loc4 = false;
                    }
                }
                else if (loc1.todayOpen && !Global.isDebugModle) 
                {
                    this._optBtn.label = Language.getString(60421);
                    loc3 = false;
                }
                else 
                {
                    this._optBtn.label = Language.getString(60407);
                }
            }
            this._difficulCb.enabled = loc2;
            this._optBtn.enabled = loc3;
            HighlightManager.instance.glowEffectButton(this._optBtn, loc4);
            return;
        }

        /* internal  */setDiffCbSelected(arg1: int): void
        {
            var loc1=0;
            var loc2=null;
            loc1 = 0;
            while (loc1 < this._diffData.length) 
            {
                loc2 = this._diffData.getItemAt(loc1);
                if (loc2["value"] == arg1) 
                {
                    this._difficulCb.selectedItem = loc2;
                    return;
                }
                ++loc1;
            }
            return;
        }

        /* internal  */updateDiffArr(): void
        {
            return;
        }

        /* internal */ /* var */_diffData: DataProvider;

        /* internal */ /* var */_numLabel: GLabel;

        /* internal */ /* var */_difficulCb: GComboBox;

        /* internal */ /* var */_descText0: GTextFiled;

        /* internal */ /* var */_descText1: GTextFiled;

        /* internal */ /* var */_descText2: GTextFiled;

        /* internal */ /* var */_optBtn: GButton;
    }
